home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / MacShell / DoEvent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-04  |  7.5 KB  |  324 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** Program:        MacShell
  5. ** File:        doevent.c
  6. ** Written by:  Eric Soldan
  7. **
  8. ** Copyright © 1990-1991 Apple Computer, Inc.
  9. ** All rights reserved.
  10. */
  11.  
  12.  
  13.  
  14. /*****************************************************************************/
  15.  
  16.  
  17.  
  18. #include "MacShell.h"            /* Get the MacShell includes/typedefs, etc.    */
  19. #include "MacShellCommon.h"        /* Get the stuff in common with rez.        */
  20. #include "MacShell.protos"        /* Get the prototypes for MacShell.            */
  21.  
  22. #ifndef __CTLHANDLER__
  23. #include "CtlHandler.h"
  24. #endif
  25.  
  26. #ifndef __DESK__
  27. #include <Desk.h>
  28. #endif
  29.  
  30. #ifndef __DISKINIT__
  31. #include <DiskInit.h>
  32. #endif
  33.  
  34. #ifndef __ERRORS__
  35. #include <Errors.h>
  36. #endif
  37.  
  38. #ifndef __MENUS__
  39. #include <Menus.h>
  40. #endif
  41.  
  42. #ifndef __TEXTEDITCONTROL__
  43. #include "TextEditControl.h"
  44. #endif
  45.  
  46. #ifndef __TOOLUTILS__
  47. #include <ToolUtils.h>
  48. #endif
  49.  
  50. #ifdef THINK_C
  51. #include "Utilities.h"
  52. #else
  53. #ifndef __UTILITIES__
  54. #include <Utilities.h>
  55. #endif
  56. #endif
  57.  
  58.  
  59.  
  60. /*****************************************************************************/
  61.  
  62.  
  63.  
  64. extern Cursor    *gCursorPtr;
  65.  
  66.  
  67.  
  68. /*****************************************************************************/
  69. /*****************************************************************************/
  70.  
  71.  
  72.  
  73. /* Do the right thing for an event.  Determine what kind of event it is, and
  74. ** call the appropriate routines.
  75. */
  76.  
  77. #pragma segment Main
  78. void    DoEvent(EventRecord *event)
  79. {
  80.     WindowPtr        window;
  81.     FileRecHndl        frHndl;
  82.     Rect            contentRct, old, growLimits;
  83.     Point            pt;
  84.     long            size;
  85.     short            part, hDocSize, vDocSize;
  86.     OSErr            err;
  87.     char            key;
  88. #if MACSHELL_VERSION
  89.     TEHandle        teHndl;
  90. #endif
  91.  
  92.     switch(event->what) {
  93.  
  94.         case nullEvent:
  95.             DoIdleTasks(event);
  96.             break;
  97.  
  98.         case mouseDown:
  99.             gCursorPtr = nil;
  100.                 /* No shortcuts when we recalculate the cursor region. */
  101.  
  102.             part = FindWindow(event->where, &window);
  103.             if (part != inContent) DoSetCursor(&qd.arrow);
  104.  
  105.             switch(part) {
  106.  
  107.                 case inContent:
  108.                     if (window != FrontWindow()) {
  109.                         SelectWindow(window);
  110.                         if (IsAppWindow(window)) {
  111.                             DoUpdate(window);
  112.                             contentRct = GetWindowContentRect(window);
  113.                             if (PtInRect(event->where, &contentRct)) DoEvent(event);
  114.                         }        /* Do first click. */
  115.                     } else DoContentClick(window, event);
  116.                     break;
  117.  
  118.                 case inDrag:            
  119.                     DragWindow(window, event->where, &qd.screenBits.bounds);
  120.                     break;        /* Pass screenBits.bounds to get all gDevices. */
  121.  
  122.                 case inGoAway:
  123.                     if (TrackGoAway(window, event->where)) DisposeOneWindow(window, iClose);
  124.                     break;
  125.  
  126.                 case inGrow:
  127.                     old = GetWindowContentRect(window);
  128.                     SetRect(&growLimits, kMinWindowWidth, kMinWindowHeight,
  129.                                          kMaxWindowWidth, kMaxWindowHeight);
  130.                     if (size = GrowWindow(window, event->where, &growLimits)) {
  131.                         pt = *(Point *)&size;
  132.                         SizeWindow(window, pt.h, pt.v, true);
  133.                         DoResizeWindow(window, old.right - old.left, old.bottom - old.top);
  134.                     }
  135.                     break;
  136.  
  137.                 case inMenuBar:        /* Process mouse menu command (if any). */
  138.                     AdjustMenus();
  139.                     DoMenuCommand(MenuSelect(event->where));
  140.                     break;
  141.  
  142.                 case inSysWindow:    /* Let the system handle the mouseDown. */
  143.                     SystemClick(event, window);
  144.                     break;
  145.  
  146.                 case inZoomIn:
  147.                 case inZoomOut:
  148.                     if (TrackBox(window, event->where, part)) {
  149.                         old = GetWindowContentRect(window);
  150.                         frHndl = (FileRecHndl)GetWRefCon(window);
  151.                         hDocSize = (*frHndl)->fileState.hDocSize;
  152.                         vDocSize = (*frHndl)->fileState.vDocSize;
  153.                         if ((*frHndl)->fileState.hScroll) hDocSize += 15;
  154.                         if ((*frHndl)->fileState.vScroll) vDocSize += 15;
  155.                         ZoomToWindowDevice(window, hDocSize, vDocSize, part, true);
  156.                         DoResizeWindow(window, old.right - old.left, old.bottom - old.top);
  157.                     }
  158.                     break;
  159.  
  160.             }
  161.             break;
  162.  
  163.         case activateEvt:
  164.             gCursorPtr = nil;
  165.                 /* No shortcuts when we recalculate the cursor region. */
  166.  
  167.             DoActivate((WindowPtr)event->message,
  168.                        (event->modifiers & activeFlag));
  169.             break;
  170.  
  171.         case autoKey:
  172.         case keyDown:                    /* Check for menukey equivalents. */
  173.             key = event->message & charCodeMask;
  174.             if (event->modifiers & cmdKey) {        /* Command key down. */
  175.                 if (event->what == keyDown) {
  176.                     AdjustMenus();
  177.                         /* Enable/disable/check menu items properly. */
  178.                     DoMenuCommand(MenuKey(key));
  179.                 }
  180.                 break;
  181.             }
  182.  
  183.             if (!IsAppWindow(window = FrontWindow())) break;
  184.  
  185.             DoContentKey(window, event);
  186.             break;
  187.  
  188.         case diskEvt:
  189.             gCursorPtr = nil;
  190.                 /* No shortcuts when we recalculate the cursor region. */
  191.  
  192.             if (HiWord(event->message) != noErr) {
  193.                 SetPt(&pt, kDILeft, kDITop);
  194.                 err = DIBadMount(pt, event->message);
  195.             }
  196.             break;        /* It is not a bad idea to at least call DIBadMount
  197.                         ** in response to a diskEvt, so that the user can
  198.                         ** format a floppy.
  199.                         */
  200.         case kHighLevelEvent:
  201.             gCursorPtr = nil;
  202.                 /* No shortcuts when we recalculate the cursor region. */
  203.  
  204.             DoHighLevelEvent(event);
  205.             break;
  206.  
  207.         case kOSEvent:
  208.             gCursorPtr = nil;
  209.                 /* No shortcuts when we recalculate the cursor region. */
  210.  
  211.             switch ((event->message >> 24) & 0xFF) {
  212.                     /* Must logical and with 0xFF to get only low byte. */
  213.                     /* High byte of message. */
  214.  
  215.                 case kMouseMovedMessage:
  216.                     break;
  217.  
  218.                 case kSuspendResumeMessage:
  219.                         /* Suspend/resume is also an activate/deactivate. */
  220.                     gInBackground = !(event->message & kResumeMask);
  221.                     DoActivate(FrontWindow(), !gInBackground);
  222.                     break;
  223.             }
  224.             break;
  225.  
  226.         case updateEvt:
  227.             DoUpdate((WindowPtr)event->message);
  228.             break;
  229.  
  230.     }
  231.  
  232.     DoCursor();
  233.     AdjustMenus();
  234.  
  235. #if MACSHELL_VERSION
  236.     if (teHndl = CTEFindActive(nil)) {
  237.         BeginContent(window = (*teHndl)->inPort);
  238.         CTEIdle();
  239.         EndContent(window);
  240.     }
  241. #endif
  242.  
  243. }
  244.  
  245.  
  246.  
  247. /*****************************************************************************/
  248.  
  249.  
  250.  
  251. /* This is called when a window is activated or deactivated. */
  252.  
  253. #pragma segment Main
  254. void    DoActivate(WindowPtr window, Boolean becomingActive)
  255. {
  256. #pragma unused (becomingActive)
  257.  
  258.     NotifyCancel();
  259.  
  260.     if (IsAppWindow(window)) {
  261.         SetPort(window);
  262.         DoCtlActivate(window);
  263.         DoDrawFrame(window);            /* Redraw window scrollbars and growIcon, if any. */
  264.         BeginContent(window);
  265.         DoDrawControls(window, true);    /* Redraw content scrollbars. */
  266.         EndContent(window);
  267.     }
  268. }
  269.  
  270.  
  271.  
  272. /*****************************************************************************/
  273.  
  274.  
  275.  
  276. /* This is called when an update event is received for a window.  First, the
  277. ** updateRgn is separated into two parts.  Part 1 holds the window frame area,
  278. ** if any.  This is the area that might hold the scrollbars, grow icon, and
  279. ** any other application-specific frame parts.  This is drawn first.  Once
  280. ** this is done, the remainder of the updateRgn is drawn.  This allows us to
  281. ** handle all of the frame clipping without using the clipRgn.  By freeing up
  282. ** the clipRgn, we allow the application to use it without having to share.
  283. */
  284.  
  285. #pragma segment Main
  286. void    DoUpdate(WindowPtr window)
  287. {
  288.     WindowPtr    oldPort;
  289.     RgnHandle    contPart, framePart;
  290.     Point        contOrg;
  291.     FileRecHndl    frHndl;
  292.  
  293.     GetPort(&oldPort);
  294.     SetPort(window);
  295.  
  296.     if (IsAppWindow(window)) {
  297.  
  298.         DoUpdateSeparate(window, &contPart, &framePart);
  299.  
  300.         if (framePart) {        /* Update the document frame, if any. */
  301.  
  302.             CopyRgn(framePart, ((WindowPeek)window)->updateRgn);
  303.             DisposeRgn(framePart);
  304.             BeginUpdate(window);
  305.             DoDrawFrame(window);
  306.             EndUpdate(window);
  307.         }
  308.         if (contPart) {            /* Update the rest of the content. */
  309.             CopyRgn(contPart, ((WindowPeek)window)->updateRgn);
  310.             DisposeRgn(contPart);
  311.             BeginUpdate(window);
  312.             GetContentOrigin(window, &contOrg);
  313.             SetOrigin(contOrg.h, contOrg.v);
  314.             frHndl = (FileRecHndl)GetWRefCon(window);
  315.             DoImageDocument(frHndl);
  316.             SetOrigin(0, 0);
  317.             EndUpdate(window);
  318.         }
  319.     }
  320. }
  321.  
  322.  
  323.  
  324.